#define _CRT_SECURE_NO_WARNINGS

////A
//#include<bits/stdc++.h>
//using namespace std;
//int a, b;
//int x;
//signed main()
//{
//	cin >> a >> b >> x;
//	cout << (x - b) / a << endl;
//	return 0;
//}



////B
//#include<bits/stdc++.h>
//using namespace std;
//const int mxn = 1e5 + 5;
//int n, m, q;
//int a[mxn], x;
//int f[mxn];
//signed main()
//{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	cin >> n >> m >> q;
//	for (int i = 1; i <= n; ++i)
//		cin >> a[i], f[a[i]]++;
//	while (q--) {
//		cin >> x;
//		cout << n - f[x] << '\n';
//	}
//	return 0;
//}



////C
#include<bits/stdc++.h>
using namespace std;
const int mxn = 4e3 + 5;
const int inf = 0xc0c0c0c0;
int n, k;
int a[mxn];
int dp[mxn];
int mx = inf;
signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)cin >> a[i], dp[i] = a[i];
	for (int i = k+2; i <= n; ++i) {
		int x = dp[i];
		for (int j = 1; j <= i-k-1; ++j) {
			dp[i] = max(dp[i], x + dp[j]);
		}
	}
	for (int i = 1; i <= n; ++i)mx = max(mx, dp[i]);
	cout << mx << '\n';
	return 0;
}




////D
//#include<bits/stdc++.h>
//using namespace std;
//const int mxn = 2e3 + 5;
//int n, m, x;
//int sx, sy, ex, ey;
//int dx[] = { 1, 0, -1, 0 };
//int dy[] = { 0, 1, 0, -1 };
//int g[mxn][mxn];
//queue<int> q;
//void bfs(int x, int y)
//{
//	for (int i = 0; i < 4; i++) {
//		int nx = x + dx[i];
//		int ny = y + dy[i];
//		if (nx < 1 || ny < 1 || nx > n || ny > m) continue;
//		if (g[nx][ny] == -1) continue;
//
//
//	}
//}
//signed main()
//{
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	cin >> n >> m >> x;
//	cin >> sx >> sy >> ex >> sy;
//	memset(g, -1, sizeof g);
//	for (int i = 1; i <= n; ++i) {
//		for (int j = 1; j <= m; ++j) {
//			cin >> g[i][j];
//		}
//	}
//
//	return 0;
//}






////F
//#include<bits/stdc++.h>
//using namespace std;
//const int mxn = 1e5 + 5;
//int t, n;
//
//signed main()
//{
//
//	return 0;
//}